home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Developer's Kit 1996
/
Delphi Developer's Kit 1996.iso
/
power
/
inmemory
/
test.pas
< prev
Wrap
Pascal/Delphi Source File
|
1995-12-22
|
3KB
|
99 lines
unit Test;
(*
This is an exmple of how to use TInMemoryTable and TTempTable.
WARNING! THIS CODE IS PROVIDED AS IS WITH NO GUARANTEES OF ANY KIND!
USE THIS AT YOUR OWN RISK - YOU ARE THE ONLY PERSON RESPONSIBLE FOR
ANY DAMAGE THIS CODE MAY CAUSE - YOU HAVE BEEN WARNED!
Having got this of my chest, more about this program:
It creates an in-memory table and then sets the DataSet property of a
DataSource control on the form to it. So the grid that you see on your
form is actually accessing an in-memory table!
If you have the VCL source and figured out how to recompile it (it's not
hard - read the readme) then you can go into DB.PAS, change the line
in TDataSet.InternalOpen that reads
FCanModify := (CursorProps.eOpenMode = dbiReadWrite) and
not CursorProps.bTempTable;
to
FCanModify := (CursorProps.eOpenMode = dbiReadWrite); { and
not CursorProps.bTempTable; }
Now just change TInMemoryTable to TTempTable in the source below - and
you have a TempTable - it's just like in-memory, but has more features.
Have Fun!
Gregory Trubetskoy INTERNET:grisha@mira.com
http://www.mira.com/home/grisha
*)
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, InMem, TempTbl,StdCtrls, DBTables, Grids, DBGrids, DB;
type
TForm1 = class(TForm)
Button1: TButton;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
MyTable: TInMemoryTable;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
MyTable := TInMemoryTable.Create(Form1);
with MyTable do begin
try
DatabaseName := 'DBDEMOS';
{ TableName can be anything - but cannot be blank or DBE will give you
an invalid parameter error }
TableName := 'xxx.db';
{ add a couple of fields }
FieldDefs.Add('F1', ftString, 5, False);
FieldDefs.Add('F2', ftString, 5, False);
CreateTable;
{ open the table }
Active := True;
{ add a couple of records }
InsertRecord(['abc', 'def']);
InsertRecord(['abc', 'def']);
{ link the grid on the form to this table }
DataSource1.DataSet := MyTable;
finally
{ these lines are moved to FormDestroy
Close;
Free; }
end;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
MyTable.Close;
MyTable.Free;
end;
end.